package org.example.util;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.UUID;

public class Backup {



    public String save(HttpServletRequest request) {
        String user = "root"; // 数据库帐号

        String password = "rootA123@"; // 数据库密码

        String database = "personnelManagement"; // 需要备份的数据库名
        UUID uuid=UUID.randomUUID();
        String upload = request.getServletContext().getRealPath("upload")+"/"+uuid+database;
        String filepath = upload; // 需要备份到的地址

        String stmt1 = "mysqldump " + database + " -u " + user + " -p" + password + " --result-file=" + filepath;

        try {

            Runtime.getRuntime().exec(stmt1);
            System.out.println("数据已导出到文件" + filepath + "中");
            return filepath;

        } catch (IOException e) {

            e.printStackTrace();

            return null;
        }

    }





}
